package modules::weather;

use module;
use vars '@ISA';
@ISA = ("module");
use DBI;
use encoding "utf8";
use utf8;
use locale;
use Weather::Google;

sub got_weather {
my ($pkg,%args) = @_;
$args{body} =~ s/погода\s+//; 
my (@words_vi) = split(/ /,$args{body});
my $gw;

return 1 unless ($words_vi[0] =~ /\w.{1,30}/);
$gw = new Weather::Google("@words_vi"); # City name
my @info;
@info = $gw->current('temp_c','humidity','wind_condition');

if (defined $info[1]) {
$info[0] =~ s/(-?\d+)/Температура: $1°C/;
$info[1] =~ s/Humidity:/Влажность:/;
$info[2] =~ s/Wind: (\w+) at (\d+) mph/Ветер: $1, скорость $2 миль\/ч/;
$info[2] =~ tr/SNWE/ЮСЗВ/;
   foreach (@info) {
      $_ = $_."\n";
   }
chomp($info[2]);
   main::SendMessage(to => $args{from}, type => 'groupchat', body => "$args{resource}:\n\u@words_vi\n@info");
} else {
   main::SendMessage(to => $args{from}, type => 'groupchat', body => "$args{resource}, нет такого города: @words_vi");
}
}

main::pd("................\n\n\n");
1;